﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StatisticReportManagement.aspx.cs" 
	Inherits="RapidWebDev.Web.Templates.Statistic.StatisticReportManagement" 
	Title="<%$ Resources:Statistic, StatisticReportManagementPageTitle%>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <meta http-equiv="Expires" content="0" />
	<meta http-equiv="Cache-Control" content="no-cache"/>
	<meta http-equiv="Pragma" content="no-cache"/>
</head>
<body>
	<form runat="server">
		<div id="StatisticTemplateSelector"></div>
	    
		<div id="StatisticReports">
			<iframe id="IFrameStatisticReports" frameborder="0" width="100%" runat="server" />
		</div>
	    
		<script type="text/javascript">
			Ext.onReady(function()
			{
				var dataStore = new Ext.data.Store(
    			{
    				proxy: new Ext.data.HttpProxy(
    				{
    					url: 'http://localhost:50682/Services/StatisticService.svc/json/GetStatisticTemplates',
    					method: 'GET'
    				}),
    				reader: new Ext.data.JsonReader(
    				{
    					root: 'StatisticTemplateObjects',
    					totalProperty: 'TotalRecordCount',
    					id: 'StatisticTemplateId'
    				},
    				[
						{ name: 'Name', mapping: 'Name' },
						{ name: 'StatisticTemplateId', mapping: 'StatisticTemplateId' },
						{ name: 'Description', mapping: 'Description' }
					])
    			});

				// customize rendering template
				var resultTpl = new Ext.XTemplate(
					'<tpl for="."><div class="search-item">',
						'<h3>{Name}</h3>',
						'{Description}',
					'</div></tpl>');

				window.StatisticTemplateSelectorPanel = new Ext.Panel(
				{
					id: 'StatisticTemplateSelectorProxy',
					renderTo: 'StatisticTemplateSelector',
					title: '<%=Resources.Statistic.StatisticTemplate%>',
					collapsed: false,
					collapsible: false,
					frame: true,
					titleCollapse: false,
					items:
					[
						new Ext.form.Label({ text: '<%=Resources.Statistic.Name%>: ' }),
						new Ext.form.ComboBox(
						{
							width: 280,
							tpl: resultTpl,
							itemSelector: 'div.search-item',
							store: dataStore,
							typeAhead: false,
							triggerAction: 'all',
							editable: false,
							pageSize: 10,
							displayField: 'Description',
							valueField: 'StatisticTemplateId',
							listeners:
							{
								select: onStatisticTemplateSelected
							}
						}),
						new Ext.form.Label({ text: '(<%=Resources.Statistic.StatisticTemplateSelectionToolTip%>)', style: 'color: #444444; padding-left: 6px' })
					]
				});

				resizeIFrame();
			});

			$(window).resize(function()
			{
				resizeIFrame();
			});

			function resizeIFrame()
			{
				$("#IFrameStatisticReports").height(document.documentElement.clientHeight - 60);
			}

			function onStatisticTemplateSelected(combo, record, index)
			{
				// change the web page inner of the iframe.
				var iframeSrcUri = '<% = Kit.ResolveAbsoluteUrl("~/StatisticReportManagement/DynamicPage.svc") %>?StatisticTemplateId=' + record.id + '&stamp=' + (new Date()).format('YmdHisu');
				alert(iframeSrcUri);
			}
		</script>
    </form>
</body>
</html>
